function getPageDescription() {
    let getDescription = url => {
        return fetch(url,{method: 'get'}).then(_ => _.text()).then(ret => {
            let r = $(ret);
            return new Promise(s => {
                let description = ``;
                r.each((ind,dom) => {
                    if (`getAttribute` in dom) {
                        let name = dom.getAttribute('name');
                        if (name === 'description') {
                            // console.log(dom.getAttribute('content'))
                            description = dom.getAttribute('content');
                        }
                    }
                });
                s(description);
            });
        });
    }
    let urls = [];
    let des = [];
    $('.video-list li a.title').each((ind,dom) => {
        urls.push(dom.getAttribute('href'));
    });
    let fetching = false;
    return new Promise(s => {
        let id = setInterval(() => {
            if (!fetching) {
                if (urls.length) {
                    fetching = true;
                    getDescription(urls.pop()).then(_des => {
                        des.push(_des);
                        fetching = false;
                    });
                } else {
                    clearInterval(id);
                    s(des);
                }
            }
        },500);
    })
}
function next() {
    console.clear();
    $('.icon-arrowdown3')[0].click();
    setTimeout(() => {
        getPageDescription().then(console.log);
    },500);
}

var AutoNext = (function() {
    function checkNext() {
        let btn = document.querySelector('#galgame .gal-bottom-desc');
        return btn && btn.innerText === '点击继续';
    }
    function toNext() {
        document.getElementsByClassName('gal-stage__clicklayer')[0].click();
    }
    return function(time = 100) {
        if (window.autoNextId) {
            clearInterval(window.autoNextId);
        }
        time = time || 100;
        window.autoNextId = setInterval(() => {
            if (checkNext()) {
                toNext();
            }
        },time);
    };
})();


